from sqlalchemy import Column, String, Integer, Float, JSON, ForeignKey
from sqlalchemy.orm import relationship
from database import Base


class GatewaySiteConfig(Base):
    __tablename__ = "gateway_site_config"

    id = Column(String(12), primary_key=True)
    name = Column(String(64), nullable=False)
    site_cat = Column(Integer, nullable=False)
    installed_date = Column(String(13))
    site_status = Column(Integer, default=0)
    order = Column(Float, nullable=False)

    clusters = relationship("GatewayClusterSite", back_populates="site")


class GatewayClusterConfig(Base):
    __tablename__ = "gateway_cluster_config"

    id = Column(String(12), primary_key=True)
    name = Column(String(64), nullable=False)
    parent_id = Column(String(12))
    order = Column(Float, nullable=False)

    sites = relationship("GatewayClusterSite", back_populates="cluster")


class GatewayClusterSite(Base):
    __tablename__ = "gateway_cluster_site"

    id = Column(String(12), primary_key=True)
    cluster_id = Column(String(12), ForeignKey('gateway_cluster_config.id'))
    site_id = Column(String(12), ForeignKey('gateway_site_config.id'))

    cluster = relationship("GatewayClusterConfig", back_populates="sites")
    site = relationship("GatewaySiteConfig", back_populates="clusters")